//
// Created by 抑~风 on 2022/11/20.
//

#include "regexp.h"
#include<string>
#include<iostream>
using namespace std;
namespace CWJ{

     unordered_map<char,RegexpLever::TokenType> RegexpLever::SPECIAL_SYMBOL_MAP{
             {'|',TokenType::OR},
             {'^',TokenType::OPPOSITE},
             {'[',TokenType::LEFT_MIDDLE},
             {']',TokenType::RIGHT_MIDDLE},
             {'(',TokenType::LEFT_SMALL},
             {')',TokenType::RIGHT_SMALL},
             {'*',TokenType::ASTERISK},
             {'?',TokenType::QUESMARK},
             {'+',TokenType::PLUS},
             {'-',TokenType::BETWEEN},
             {'\\',TokenType::TRANSFORM},
             {'.',TokenType::DOT},
     };

    RegexpLever::TokenList RegexpLever::tokenize(const string& script){
        char c = 0;
        this->tokens.clear();
        for(char i : script){
            c = i;
            if(RegexpLever::SPECIAL_SYMBOL_MAP.count(c)){
                auto& tp = RegexpLever::SPECIAL_SYMBOL_MAP[c];
                this->tokens.emplace_back(tp,static_cast<unsigned int>(tp),c);

            }else if(c == ' ' || c == '\n' || c== '\t'){
                continue;
            }else{
                auto tp = TokenType::CHAR;
                this->tokens.emplace_back(tp,static_cast<unsigned int>(tp),c);
            }
        }

//        for(auto & c : this->tokens){
//            cout<<c.getConText()<<" "<<(unsigned int)c.getType()<< " "<<(unsigned )TokenType::OR<<endl;
//        }

        return std::move(this->tokens);
    }
}


